#ifndef DATAANALYSIS_H
#define DATAANALYSIS_H
#include <QObject>
#include <QVariant>
#include <QVariantList>
#include <QVariantMap>
#include <QRandomGenerator>
#include <QQuickItem>
#include <QTime>
#include <QWidget>
#include <QTextCodec>
#include <QLabel>
#include <QHBoxLayout>
#include <QQuickWidget>
#include <QFile>
#include <QFileDialog>
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QMainWindow>
#include "widgetanchor.h"
#include "pcrState.h"
#include <cmath>

// 1. 数据分析
// 2. 维护图表显示状态
class DataAnalysis : public QObject
{
    Q_OBJECT

public:
    DataAnalysis();
    ~DataAnalysis();


    Q_INVOKABLE QVariantMap openLocalAnalysis(QString expId);  // 将本地存储的Wlk文件导入到Temp表中，再进行数据分析

    Q_INVOKABLE void openAnalysis(QString equId);   // 没有设备Id时，从Temp里读取数据。有设备Id时， 查找设备Id对应的ExperimentId，读取数据 (open后，后续的操作都是基于当前Open的数据分析)
    Q_INVOKABLE void closeAnalysis(QString equId);


    Q_INVOKABLE QVariantMap getAnalysisState();     // 获取当前分析状态 (是否可进行数据分析、是否可进行标准曲线计算等)

    // 颜色设置
    Q_INVOKABLE void setColor(QVariantMap colorList);
    Q_INVOKABLE void setColor_posi(QVariantMap  colorMap);        // QVariantMap <key-样本名称, value-颜色>

    // 状态变更
    Q_INVOKABLE void changePage(int pageIdx);
    Q_INVOKABLE void changeChart(int chartIdx);
    Q_INVOKABLE void updateFilter_channel(QVariantList list);
    Q_INVOKABLE void updateFilter_posi(QVariantList list);
    Q_INVOKABLE void updateFilter_name(QVariantList list);
    Q_INVOKABLE void updateFilter_type(QVariantList list);

    Q_INVOKABLE QVariantList getFilterList_channel();
    Q_INVOKABLE QVariantList getFilterList_name();
    Q_INVOKABLE QVariantList getFilterList_type();
    Q_INVOKABLE QVariantList getFilterList_posi();
    Q_INVOKABLE QVariantList getList_channel();
    Q_INVOKABLE QVariantList getList_name();
    Q_INVOKABLE QVariantList getList_type();
    Q_INVOKABLE QVariantList getList_posi();

    // 阈值线 (阈值线区分于图表 单独绘制)
    Q_INVOKABLE void         setThresholdVisible(bool visible);
    Q_INVOKABLE QVariantList getThrPosi();
    Q_INVOKABLE void         changeThr(int channel, double value);

    Q_INVOKABLE QVariantList getGuideTable1();
    Q_INVOKABLE QVariantList getGuideTable2(QString type = "");
    Q_INVOKABLE QString      getGuideLabel(QString type = "");
    Q_INVOKABLE QVariantList getNum();

    Q_INVOKABLE QVariantMap  getModelConfig();
    Q_INVOKABLE void         setModelConfig(QVariantMap);

    Q_INVOKABLE int         datao();        // 0导出失败 1导出成功
    Q_INVOKABLE int         exportImage();

    // pState向QML同步当前状态
    Q_INVOKABLE int          getCurrentChart();
    Q_INVOKABLE int          getCurrentPage();
//    Q_INVOKABLE QStringList  getCurrentChannel();

    // 样本表格
    Q_INVOKABLE QVariantList getSampleTable();
    Q_INVOKABLE void         updateSampleTableSelected(QVariantList sampleList);
    Q_INVOKABLE void         updateSampleTableSorted(int index);

    Q_INVOKABLE QVariantMap  getStandardInfo();

    // 图
    Q_INVOKABLE QVariantMap  getChartData();


signals:
    void tableChanged();

private slots:
    void onTableChanged();


private:


    QMap<QString, PCRState*>    _states;
    PCRState*                   pState = nullptr;

    QString                     _currentEquId;

};

#endif // DATAANALYSIS_H
